<?
include("includes/functions.php");
if (!empty($uUID)) {
	// Get User Name
	$sql = "SELECT FullName from ss_users WHERE UserID = '$uUID'";
	$result = mysql_db_query($dbname,$sql);
	$row = mysql_fetch_row($result);
	$userName = $row[0];
}

if (!empty($delete)) {	
	$message = "User <b>$userName</b> has been deleted.";
	
	// Delete User
	$sql = "DELETE from oa_sys_Users2 WHERE User_PID = '$uUID'";
	$result = mysql_db_query($dbname,$sql);
}
if (!empty($add)) {
	$message = "User <b>$userName</b> has been added as an admin user.";
}
if (!empty($edit)) {
	$message = "User <b>$userName</b> has been updated.";
}


// Get all users
$sql = "SELECT * from ss_users ORDER BY LastName";
$result = mysql_db_query($dbname,$sql);
$rows = mysql_num_rows($result);

include("includes/header.php"); ?>
<script language="JavaScript">
function confirmSubmit() {
	var agree=confirm("Are you sure you want to delete this Admin User?");
	if (agree)
		return true ;
	else
		return false ;
}
</script>
<div id="header2">
	<? include("includes/main_menu.php"); ?>
</div>
<? include("includes/sub_menu_stats.php"); ?>
<div id="subNoLogin"></div>
<div id="pageHeader"><h1 class="headerUsers">Website Statistics <b></b></h1></div>

<div id="pageInstructions"><img src="images/help.gif"> <br><br>

<?
if (!empty($message)) { echo "<font color=red>$message</font>\n"; }
?>
<p></p>
</div>

<div id="datatable">

<form action="<?=$PHP_SELF; ?>?makeVisible=1&<?=$linkString; ?>" method="POST">
<input type="hidden" name="page" value="<?=$page; ?>">
<input type="hidden" name="start" value="<?=$start; ?>">
<input type="hidden" name="limit" value="<?=$limit; ?>">
<input type="hidden" name="search" value="<?=$search; ?>">

<table class="datatable" summary="A List of Current Admin Users">
	<caption>Current Admin Users</caption>
	
	<? if ($rows > 0) { ?>
	<tr>
		<th scope="col"></th>
		<th scope="col">User Full Name</th>
		<th scope="col">Login User Name</th>
		<th scope="col">Login Password</th>
		<th scope="col">Email</th>
		<th scope="col">User Level</th>
	</tr>
	<?
	$i = 0;
	while ($value = mysql_fetch_assoc($result)) {	
		if (($i % 2) > 0) { $class = "altrow"; $bgcolor = "#eeeeee"; }
		else { $class = null; $bgcolor = "#ffffff"; }
		
		$uUID       = $value[User_PID];
		$uName     = $value[UserNameFull];
  		$uUserid   = $value[UserLogonName];
  		$uPassword = $value[UserLogonPass];
  		$uEmail    = $value[UserEmailAddress];
  		$uLevel    = $value[UserAccountLevel];
  		
  		$uLinkEmail = $uEmail;
  		
  		if (strlen($uUserid) > 25) { $uUserid = substr($uUserid,0,25)."..."; }
  		if (strlen($uEmail) > 25) { $uEmail = substr($uEmail,0,25)."..."; }
  		
  		switch ($uLevel) {
  			case 1:
   			$uLevelText = "<font color=#FF6600>Data Entry</font>";
   			break;
   			case 2:
   			$uLevelText = "<font color=blue>Data Manager</font>";
   			break;
   			case 3:
   			$uLevelText = "<font color=#339900>Super User</font>";
   			break;
     	}

	?>
	<tr class="<?=$class; ?>" onmouseover="setPointer(this, '#E9FCB2')" onmouseout="setPointer(this, '<?=$bgcolor; ?>')">
	
		<td class="nav"><div class="buttons"></a><a href="user_edit.php?uUID=<?=$uUID; ?>" class="buttonEdit" title="Edit This User"><i>Edit</i></a><a href="<?=$PHP_SELF; ?>?delete=1&uUID=<?=$uUID; ?>" class="buttonDelete" onclick="return confirmSubmit();" title="Delete This User"><i>Delete</i></a></div></td>
		<td><?=$uName; ?></td>
		<td><b><?=$uUserid; ?></b></td>
		<td><b><?=$uPassword; ?></b></td>
		<td><a href="mailto:<?=$uEmail; ?>" title="Send Email to <?=$uName; ?>: [<?=$uLinkEmail; ?>]"><?=$uEmail; ?></a></td>
		<td><?=$uLevelText; ?></td>
	</tr>
	<?  $i++; }
		} else { ?>
	<tr><td>
	There are no users entered at this time.
	</td></tr>
	<? } ?>
	
</table>
</div>		


<? include("includes/footer.php"); ?>